﻿
function LoadCityDropDown() {
    locationCount = 1;
    var listCityJson;
    var s = $("<select 'id=ddlCity' />");
    $.ajax({
        type: "POST",
        url: "HandlerSearchCV.ashx",
        data: { 'search': 'city' },
        dataType: "json",
        success: function (responseData, status, xhr) {
            listCityJson = responseData;
            $.each(responseData, function (i, item) {
                s.append($("<option></option>").val(i).html(responseData[i]));

            });

        },      

        error: function (responseData, status, xhr) {
            alert(responseData.toString());
        }
    });

    s.appendTo('#Location');
    $('#Location').append("<br />");

     $("button[id^='locationAdd']").live("click", null, function () {
        locationCount++;
        var ddlDiv = $("<div id='ddlDiv'></div>")
        var select = $("<select 'id=ddlCity'" + locationCount + " />");
        $.each(listCityJson, function (i, item) {
            select.append($("<option></option>").val(i).html(listCityJson[i]));
        });

        select.appendTo(ddlDiv)
        var btnDelLoc = "btnDelLoc" + locationCount;
        ddlDiv.append("<button id='" + btnDelLoc + "' class=\"buttonDel\" >X</button>");
        ddlDiv.appendTo('#Location');
        return false;
    })

    $("button[id^='btnDelLoc']").live("click", null, function () {
        var select = $(this).parent();
        select.remove();

        return false;
    });

    
   
}